package com.simnim.io.accessibility;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity implements OnClickListener {
	private static final int DIALOG_ERROR = 1;
	private EditText query;
	private Button button;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        query = (EditText)findViewById(R.id.search_query);
        button = (Button)findViewById(android.R.id.button1);
        button.setOnClickListener(this);
    }
    
    @Override
    protected Dialog onCreateDialog(int id) {
    	if(id == DIALOG_ERROR) {
    		AlertDialog.Builder b = new AlertDialog.Builder(this);
    		b.setMessage(getResources().getString(R.string.diag_query_error));
    		b.setTitle(getResources().getString(R.string.diag_query_title));
    		return b.create();
    	}else {
    		return super.onCreateDialog(id);
    	}
    }
    
    public void onClick(View v) {
    	String q = query.getText().toString().trim();
    	if(q.length() == 0) {
    		showDialog(DIALOG_ERROR);
    	}
    	Intent i = new Intent(this, SearchYouTubeActivity.class);
    	i.putExtra("query", query.getText().toString());
    	startActivity(i);
    }
}